package com.yu.controller;

import com.yu.annotation.Log;
import com.yu.pojo.Emp;
import com.yu.pojo.vo.EmpVo;
import com.yu.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    private EmpService empService;

//    @GetMapping
//    public void findByPage(@RequestParam("page") String page,
//                           @RequestParam("pageSize") String pageSize,
//                           @RequestParam("name") String name,
//                           @RequestParam("gender") String gender,
//                           @RequestParam("begin") String begin,
//                           @RequestParam("end") String end){
//        System.out.println("page = " + page);
//        System.out.println("pageSize = " + pageSize);
//        System.out.println("name = " + name);
//        System.out.println("gender = " + gender);
//        System.out.println("begin = " + begin);
//        System.out.println("end = " + end);
//    }

    @GetMapping
    public String findByPage(EmpVo empVo){
        String result = empService.findByPage(empVo);
        System.out.println("empVo = " + empVo);
        return result;
    }

//    TODO:路径参数的参数名需要与传过来的属性名一致
    @Log
    @DeleteMapping("/{ids}")
    public String deleteByIds(@PathVariable("ids") List<Integer> ids){
        String result = empService.deleteByIds(ids);
        return result;
    }

    @Log
    @PostMapping
    public String addEmp(@RequestBody Emp emp){
        System.out.println("emp = " + emp);
        String result = empService.addEmp(emp);
        return result;
    }

    @GetMapping("/{id}")
    public String findEmpById(@PathVariable Integer id){
        System.out.println("id = " + id);
        String result = empService.findEmpById(id);
        return result;
    }

    @Log
    @PutMapping
    public String updateEmp(@RequestBody Emp emp){
        System.out.println("emp = " + emp);
        String result = empService.updateEmp(emp);
        return result;
    }
}
